package asteroids.model.expressions;

import exceptions.IllegalOperandException;
import asteroids.model.FlyingObject;

/**
 * A subclass of expression (E) that represents ginving you the y-co of the positionvector of a given entity (gety e).
 * @version 1.0
 * 
 * @author	Thijs Peirelinck & Wouter Parys
 *
 */
public class GetY extends Get {

	public GetY(E e){
		super(e);
	}
	
	@Override
	public Double getValue() throws IllegalOperandException{
		if(this.isValidExpression() == false) { throw new IllegalOperandException(); } 
		return ((FlyingObject)getOperand().getValue()).getPositionY();
	}
	
	@Override
	public boolean isValidExpression() {
		return getOperand().getReturnType().equals("entity");
	}
	
	@Override
	public String toString() {
		return "y";
	}

	@Override
	public E createCopy() {
		return new GetY(getOperand());
	}
}
